cmake_minimum_required(VERSION 3.10)
project(web_capture)

# 设置C++标准为C++17（解决结构化绑定和filesystem问题）
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if(CMAKE_BUILD_TYPE STREQUAL "Release")
    # 设置全局Release模式优化选项
    set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -march=native -DNDEBUG -ffast-math")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.1 -msse4.2 -mavx -mavx2")
    
    # 确保dlib使用相同优化
    set(DLIB_ENABLE_ASSERTS OFF CACHE BOOL "Disable asserts" FORCE)
    add_compile_definitions(DLIB_DISABLE_ASSERTS)
endif()

# 查找OpenCV
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})

# 添加 dlib 子目录（从源码构建）
add_subdirectory(../dlib dlib_build)

# 查找 MJPEG Streamer
find_package(nadjieb_mjpeg_streamer REQUIRED)

# 包含头文件目录
include_directories(
    ${CMAKE_SOURCE_DIR}/include
    ${CMAKE_SOURCE_DIR}
)

# 添加可执行文件
add_executable(web_capture
    web_capture.cpp
    FaceRecognizer.cpp
    ConfigParser.cpp
    PerformanceTimer.cpp
)

# 链接库
target_link_libraries(web_capture
    dlib::dlib
    ${OpenCV_LIBS}
    nadjieb_mjpeg_streamer::nadjieb_mjpeg_streamer
)